{include file="comm/header"}
<link rel="stylesheet" href="/assets/css/login.css">
<div class="login-wrapper">
    <form class="layui-form">
        <h2>用户注册</h2>
        <div class="layui-form-item layui-input-icon-group">
            <i class="layui-icon layui-icon-username"></i>
            <input class="layui-input" name="username" placeholder="请输入用户名" autocomplete="off"
                   lay-verType="tips" lay-verify="required" required/>
        </div>

        <div class="layui-form-item layui-input-icon-group">
            <i class="layui-icon layui-icon-password"></i>
            <input type="password" name="password" lay-verify="required"  placeholder="密码"
                   class="layui-input">
        </div>
        <div class="layui-form-item layui-input-icon-group">
            <i class="layui-icon layui-icon-password"></i>
            <input type="password"  lay-verify="required"  placeholder="确认密码"
                   class="layui-input">
        </div>
        <div class="layui-form-item layui-input-icon-group">
            <i class="layui-icon layui-icon-email"></i>
            <input type="text" name="email" lay-verify="required|email"  placeholder="邮箱，用于找回密码"
                   class="layui-input">
        </div>
        <div class="layui-form-item">
            <button class="layui-btn layui-btn-fluid layui-btn-danger" id="reg" lay-submit="" lay-filter="reg">注册</button>
        </div>
        <div class="layui-form-item" style="margin-bottom: 20px;">
            <a href="index.html">已有账号，去登录</a>
        </div>
    </form>
</div>
{include file="comm/footer"}
<script>
    layui.use(['layer', 'form','jquery'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var steps = layui.steps;
        /* 表单提交 */
        form.on('submit(reg)', function (data) {
            $.ajax({
                url: "{:url('admin/login/register')}",
                data: data.field,
                dataType: 'json',
                type: 'post',
                beforeSend: function () {
                    $("#reg").attr("disabled", "disabled").addClass('layui-btn-disabled').text('正在注册...');
                },
                success: function (res) {
                    if (res.code == 1) {
                        layer.msg('注册成功,正在跳转...', {
                            icon: 1, time: 1000 //1秒关闭（如果不配置，默认是3秒）
                        }, function () {
                            location.href = res.url;
                        });
                    } else {
                        $("#reg").removeAttr("disabled").removeClass('layui-btn-disabled').text('注册');
                        layer.msg(res.msg, {icon:2});
                    }
                }
            });
            return false;
        });

    });
</script>